package com.jiuzhe.commercial.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * Created by huanghao on 2018/6/7.
 */

public class DateUtils {
    private static String mYear; // 当前年
    private static String mMonth; // 月
    private static String mDay;
    private static String mWay;


    /**
     * 获取当前年月日
     *
     * @return
     */
    public static String getDateString() {
        final Calendar c = Calendar.getInstance();
        mYear = String.valueOf(c.get(Calendar.YEAR));// 获取当前年份
        mMonth = String.valueOf(c.get(Calendar.MONTH) + 1);// 获取当前月份
        mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH));// 获取当前月份的日期号码
        int month = Integer.parseInt(mMonth);
        int day = Integer.parseInt(mDay);
        if(month< 10){
            mMonth = "0" + mMonth ;
        }
        if (day <10 ){
            mDay = "0" + mDay ;
        }
        return mYear + "-" + mMonth + "-" + mDay;
    }


    //获取今天往后一周的日期（年-月-日）
    public static List<String> get7date() {
        List<String> dates = new ArrayList<String>();
        final Calendar c = Calendar.getInstance();
        java.text.SimpleDateFormat sim = new java.text.SimpleDateFormat("yyyy-MM-dd");
        String date = sim.format(c.getTime());
        dates.add(date);
        for (int i = 0; i < 13; i++) {
            c.add(java.util.Calendar.DAY_OF_MONTH, 1);
            date = sim.format(c.getTime());
            dates.add(date);
        }
        return dates;
    }

    /**
     * 获取当前是周几
     *
     */
    public static String getWeekString() {
        final Calendar c = Calendar.getInstance();
        mWay = String.valueOf(c.get(Calendar.DAY_OF_WEEK));
        if ("1".equals(mWay)) {
            mWay = "天";
        } else if ("2".equals(mWay)) {
            mWay = "一";
        } else if ("3".equals(mWay)) {
            mWay = "二";
        } else if ("4".equals(mWay)) {
            mWay = "三";
        } else if ("5".equals(mWay)) {
            mWay = "四";
        } else if ("6".equals(mWay)) {
            mWay = "五";
        } else if ("7".equals(mWay)) {
            mWay = "六";
        }
        return mWay;
    }

    public static String getWeek(String pTime) {
        String Week = "";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        try {
            c.setTime(format.parse(pTime));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Week = String.valueOf(c.get(Calendar.DAY_OF_WEEK));
        if ("1".equals(Week)) {
            Week = "日";
        }
        if ("2".equals(Week)) {
            Week = "一";
        }
        if ("3".equals(Week)) {
            Week = "二";
        }
        if ("4".equals(Week)) {
            Week = "三";
        }
        if ("5".equals(Week)) {
            Week = "四";
        }
        if ("6".equals(Week)) {
            Week = "五";
        }
        if ("7".equals(Week)) {
            Week = "六";
        }
        return Week;
    }
}